﻿<!--#include file="conn.asp"#-->
<!--#include file="sessao.asp"#-->
<!--#include file="getsessao.asp"#-->
<!--#include file="fn_combo.asp"#-->
<!--#include file="fn_table.asp"#-->
<%
Select Case request("acao")
	Case "getAreas"
		getAreas()
	Case "getEditarArea"
		getEditarArea()
	Case "getStatus"
		getStatus()		
End Select

Sub getAreas()
	Dim db_string
	db_string = "select a.desc_area as [Área], "
	db_string = db_string & " t.desc_tipo as [Tipo],"
	db_string = db_string & " sa.desc_status as [Status],"
	db_string = db_string & " '<a href=''#'' class=''botao ico'' onclick=''return getEditarArea('+convert(varchar,a.cod_area)+');''><span class=''edit''></span></a> ' "
	db_string = db_string & " as [Ações] "
	db_string = db_string & " from informacao.tb_areas as a "
	db_string = db_string & " inner join informacao.tb_usuario_tipo as t on t.cod_usuario_tipo=a.cod_usuario_tipo "
	db_string = db_string & " inner join informacao.tb_status_area as sa on sa.cod_status_area = a.cod_status_area "

	db_string = db_string & " where 1=1 "
	if request("nome") <> "" then
		db_string = db_string & " and (a.desc_area like '%"&request("nome")&"%' "
		db_string = db_string & " or t.desc_tipo like '%"&request("nome")&"%') "
	end if

	Dim pg_sel
	if request("pg_sel") = "" then
		pg_sel = 1
	else
		pg_sel = cdbl(request("pg_sel"))
	end if

	response.write Table("list", db_string, "tabela", true, pg_sel, 10, "getAreas(!@#)")	
End Sub

Sub getStatus()
	Dim db_string
	db_string = " SELECT * FROM informacao.tb_status_area ORDER BY desc_status "
	retorno  = fn_combo(db_string,true,"")
	response.write retorno
End Sub


Sub getEditarArea()
	Dim db_string
	Dim rsArea
	if request("cod_area") <> "" then
		db_string = " select a.cod_area, a.desc_area,a.cod_status_area, sa.desc_status,a.cod_usuario_tipo"
		db_string = db_string & " FROM informacao.tb_areas AS a "
		db_string = db_string & " INNER JOIN informacao.tb_status_area AS sa "
		db_string = db_string & " 	ON sa.cod_status_area = a.cod_status_area "
		db_string = db_string & " where a.cod_area="&request("cod_area")
		set rsArea = getRs(db_string)
		if not rsArea.eof then
			retorno = "{success : true, data: {"
		    retorno = retorno & "'nome':'"&rsArea("desc_area")&"' ,"
		    retorno = retorno & "'cod_usuario_tipo':'"&rsArea("cod_usuario_tipo")&"' ,"
		    retorno = retorno & "'cod_area':'"&rsArea("cod_area")&"' ,"
		    retorno = retorno & "'desc_status':'"&rsArea("desc_status")&"' ,"
		    retorno = retorno & "'cod_status':'"&rsArea("cod_status_area")&"' }"
			retorno = retorno & "}"
		End If
		rsArea.close
	End If
	set rsArea = nothing
	response.write retorno
End Sub


%>